package com.next.androidintentlibrary;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.app.Context;
import ohos.utils.net.Uri;

public class SettingIntents {
    private Context context;
    private Intent intent;

    private SettingIntents(Context context)
    {
        this.context = context;
    }

    public static SettingIntents from(Context context)
    {
        return new SettingIntents(context);
    }

    public SettingIntents setting()
    {
        intent = new Intent();
        intent.setAction("android.settings.SETTINGS");
        return this;
    }

    public SettingIntents apnSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.APN_SETTINGS");
        return this;
    }

    public SettingIntents bluetoothSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.BLUETOOTH_SETTINGS");
        return this;
    }

    public SettingIntents dateSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.DATE_SETTINGS");
        return this;
    }

    public SettingIntents displaySetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.DISPLAY_SETTINGS");
        return this;
    }

    public SettingIntents localeSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.LOCALE_SETTINGS");
        return this;
    }

    public SettingIntents securitySetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.SECURITY_SETTINGS");
        return this;
    }

    public SettingIntents wifiSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.WIFI_SETTINGS");
        return this;
    }

    public SettingIntents wirelessSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.WIRELESS_SETTINGS");
        return this;
    }

    public SettingIntents accessibilitySetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.ACCESSIBILITY_SETTINGS");
        return this;
    }

    public SettingIntents applicationSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.APPLICATION_SETTINGS");
        return this;
    }


    public SettingIntents captioningSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.CAPTIONING_SETTINGS");
        return this;
    }


    public SettingIntents castSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.CAST_SETTINGS");
        return this;
    }


    public SettingIntents dreamSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.DREAM_SETTINGS");
        return this;
    }

    public SettingIntents airplaneModeSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.AIRPLANE_MODE_SETTINGS");
        return this;
    }

    public SettingIntents inputMethodSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.INPUT_METHOD_SETTINGS");
        return this;
    }

    public SettingIntents locationSourceSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.LOCATION_SOURCE_SETTINGS");
        return this;
    }

    public SettingIntents internalStorageSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.INTERNAL_STORAGE_SETTINGS");
        return this;
    }

    public SettingIntents memoryCardSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.MEMORY_CARD_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public SettingIntents homeSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.HOME_SETTINGS");
        return this;
    }

    public SettingIntents nfcSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.NFC_SETTINGS");
        return this;
    }

    public SettingIntents nfcSharingSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.NFCSHARING_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public SettingIntents nfcPaymentSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.NFC_PAYMENT_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public SettingIntents printSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.ACTION_PRINT_SETTINGS");
        return this;
    }

    public SettingIntents privacySetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.PRIVACY_SETTINGS");
        return this;
    }

    public SettingIntents searchSetting()
    {
        intent = new Intent();
        intent.setAction("android.search.action.SEARCH_SETTINGS");
        return this;
    }

    public SettingIntents soundSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.SOUND_SETTINGS");
        return this;
    }

    public SettingIntents syncSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.SYNC_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.N)
    public SettingIntents webViewSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.WEBVIEW_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.N)
    public SettingIntents vpnSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.VPN_SETTINGS");
        return this;
    }

    public SettingIntents applicationDetailSetting(String packageName)
    {
        intent = new Intent();
        intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
        intent.setUri(Uri.parse("package:" + packageName));
        return this;
    }

    public SettingIntents applicationDevelopmentSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.APPLICATION_DEVELOPMENT_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
    public SettingIntents batterySaverSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.BATTERY_SAVER_SETTINGS");
        return this;
    }

    public SettingIntents dataRoamingSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.DATA_ROAMING_SETTINGS");
        return this;
    }

    public SettingIntents deviceInfoSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.DEVICE_INFO_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.N)
    public SettingIntents hardKeyboardSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.HARD_KEYBOARD_SETTINGS");
        return this;
    }

    public SettingIntents manageApplicationSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.MANAGE_APPLICATIONS_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.M)
    public SettingIntents manageWriteSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.action.MANAGE_WRITE_SETTINGS");
        return this;
    }

    public SettingIntents networkOperatorSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.NETWORK_OPERATOR_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
    public SettingIntents notificationListenerSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
        return this;
    }

    // TODO: error on device
    private SettingIntents quickLaunchSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.QUICK_LAUNCH_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public SettingIntents usageAccessSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.USAGE_ACCESS_SETTINGS");
        return this;
    }

    public SettingIntents userDictionarySetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.USER_DICTIONARY_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public SettingIntents voiceInputSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.VOICE_INPUT_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.N)
    public SettingIntents vrListenerSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.VR_LISTENER_SETTINGS");
        return this;
    }

    public SettingIntents wifiIpSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.WIFI_IP_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.M)
    public SettingIntents ignoreBatteryOptimizationSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS");
        return this;
    }

    public SettingIntents manageAllApplicationSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.MANAGE_ALL_APPLICATIONS_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.N)
    public SettingIntents manageDefaultAppsSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.MANAGE_DEFAULT_APPS_SETTINGS");
        return this;
    }

    public SettingIntents inputMethodSubtypeSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.INPUT_METHOD_SUBTYPE_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.M)
    public SettingIntents notificationPolicyAccessSetting()
    {
        intent = new Intent();
        intent.setAction("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS");
        return this;
    }

    //@RequiresApi(api = Build.VERSION_CODES.N)
    public SettingIntents ignoreBackgroundDataRestrictionsSetting(String packageName)
    {
        intent = new Intent();
        intent.setAction("android.settings.IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS");
        intent.setUri(Uri.parse("package:" + packageName));
        return this;
    }

    public Intent build()
    {
        return intent;
    }

    private void startAbility(Intent intent)
    {
        if (!(context instanceof Ability))
        {
            intent.addFlags(Intent.FLAG_ABILITY_NEW_MISSION);
        }
        context.startAbility(intent,0);
    }

    public void show()
    {
        startAbility(build());
    }
}
